package com.ncp.servlet.bbs;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ncp.model.biz.bbs.ReplyProcess;

public class ReplyServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String reply=request.getParameter("reply");
		String type=request.getParameter("type");
		int id=Integer.parseInt(request.getParameter("id"));
		//System.out.println("id="+id);
		ReplyProcess rp=new ReplyProcess();
		HttpSession session=request.getSession();
		String name=(String)session.getAttribute("LoginName");
		if(name==null){
			response.sendRedirect("index.jsp");
			return;
		}
		//System.out.println("name="+name);
		if(type.equals("direct")){
			if(rp.PostReply(id, reply,name)){
				response.sendRedirect("ShowReplyServlet?id="+id);
			}
		}else{
			int rootid=Integer.parseInt(request.getParameter("rootid"));
			if(rp.PostReply(id, rootid, reply,name)){
				response.sendRedirect("ShowReplyServlet?id="+rootid);
			}
		}
		
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}

}
